package services

import (
	"go_web/src/domain"
	"go_web/src/repositories"
)

type OrderService struct {
	op repositories.OrderRepository
	up repositories.UserRepository
}

func NewOrderService(op repositories.OrderRepository, up repositories.UserRepository) OrderService {
	return OrderService{op: op, up: up}
}

// Create 新建订单
func (us OrderService) Create(order *domain.Order) error {
	return us.op.Create(order)
}

// UpdateByID 修改订单
func (us OrderService) UpdateByID(id uint, price float64, num int16) error {
	return us.op.UpdateByID(id, price, num)
}

// DeleteByID 删除订单
func (us OrderService) DeleteByID(id uint) error {
	return us.op.DeleteByID(id)
}

// FindByOrderNum 查询订单
func (us OrderService) FindByOrderNum(orderNum string) (*domain.Order, error) {
	return us.op.FindByOrderNum(orderNum)
}

// FindByUserId 通过名称查询所有订单
func (us OrderService) FindByUserId(userId uint) (*[]domain.Order, error) {
	return us.op.FindByUserId(userId)
}
